home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / Newton Platform Info / Newton 2.0 Sample Code / Views / DatePick-2 / DatePick.text < prev    next >
Encoding:
Text File  |  1995-11-20  |  6.1 KB  |  219 lines  |  [TEXT/MPS ]

  1. // Text of project DatePick written on 11/20/95 at 5:51 PM
  2. // Beginning of file protoDatePicker
  3.  
  4. // Before Script for "protoDatePicker"
  5. // Copyright 1993-1995 Apple Computer, Inc.
  6.  
  7.  
  8. protoDatePicker :=
  9.     {viewFlags: 1,
  10.      viewFormat: nil,
  11.      viewBounds: {left: 0, top: 0, right: 120, bottom: 100},
  12.      monthChangedScript:
  13.        func()
  14.        begin
  15.            // This will be inherited by the child month view and called every time
  16.            // the user taps on a new day.  It *must* be here because the user can
  17.            // tap on days at the end or beginning of the previous or next month
  18.            // (the blank spaces on the view) and actually change the date!
  19.            // If this script isn't here to update the view and the title string,
  20.            // the month with change but the display won't--confusing the heck out of
  21.            // people.
  22.            :Dirty();
  23.            :SetTitle();
  24.        end,
  25.      monthYearSpec:
  26.        GetDateStringSpec([
  27.                [kElementMonth, kFormatLong],
  28.                [kElementYear,  kFormatLong]]),
  29.      SetTitle:
  30.        // This function updates the month/year label.  It should be called
  31.        // whenever the user changes the date.
  32.        
  33.        func()
  34.        begin
  35.            SetValue(monthYearLabel, 'text,
  36.                     LongDateStr(selectedDates[0], monthYearSpec));
  37.        end,
  38.      viewSetupDoneScript:
  39.        func()
  40.        begin
  41.            if NOT selectedDates exists then
  42.                self.selectedDates := [Time()];  // initialize selectedDates to current
  43.            :SetTitle();
  44.        end,
  45.      Refresh:
  46.        // This allows scripts outside the proto to have a nice entry point for
  47.        // getting the picker refreshed when the selectedDates array changes.
  48.        
  49.        func()
  50.        begin
  51.            monthView:Dirty();
  52.            :SetTitle();
  53.        end,
  54.      debug: "protoDatePicker",
  55.      viewClass: 74
  56.     };
  57.  
  58. monthYearLabel :=
  59.     {text: "",
  60.      viewBounds: {left: 0, top: 0, right: 0, bottom: 15},
  61.      viewFlags: 3,
  62.      viewJustify: 8388662,
  63.      debug: "monthYearLabel",
  64.      _proto: @218
  65.     };
  66. AddStepForm(protoDatePicker, monthYearLabel);
  67. StepDeclare(protoDatePicker, monthYearLabel, 'monthYearLabel);
  68.  
  69.  
  70.  
  71. previousMonthButton :=
  72.     {viewBounds: {left: 0, top: 0, right: 15, bottom: 15},
  73.      viewSetupFormScript:
  74.        func()
  75.        begin
  76.            // initialize the icon from the system bitmap via a magic pointer.
  77.            self.icon := ROM_leftBitmap;    // leftBitmap
  78.        end,
  79.      viewFlags: 515,
  80.      viewJustify: 6,
  81.      viewFormat: 1,
  82.      buttonPressedScript:
  83.        func()
  84.        begin
  85.            // move to the previous month, and make sure the views redraw.
  86.            selectedDates[0] := IncrementMonth(selectedDates[0], -1);
  87.            monthView:dirty();
  88.            :SetTitle();
  89.        
  90.            // have to call RefreshViews because this is the buttonPressedScript,
  91.            // the view otherwise wouldn't get refreshed until the user lifted the
  92.            // pen!  If you had done this in the buttonClickScript instead, you
  93.            // could skip the RefreshViews() call.
  94.            RefreshViews();
  95.        end,
  96.      icon: nil,
  97.      debug: "previousMonthButton",
  98.      _proto: @198
  99.     };
  100. AddStepForm(protoDatePicker, previousMonthButton);
  101.  
  102.  
  103.  
  104. nextMonthButton :=
  105.     {icon: nil,
  106.      viewBounds: {top: 0, left: -15, right: 0, bottom: 15},
  107.      viewSetupFormScript:
  108.        func()
  109.        begin
  110.            // initialize the bitmap from the system ROMs via a magic pointer.
  111.            self.icon := ROM_rightBitmap;    // rightBitmap
  112.        end,
  113.      viewFlags: 515,
  114.      viewFormat: 1,
  115.      viewJustify: 38,
  116.      buttonPressedScript:
  117.        func()
  118.        begin
  119.            // move to the previous month, and make sure the views redraw.
  120.            selectedDates[0] := IncrementMonth(selectedDates[0], 1);
  121.            monthView:dirty();
  122.            :SetTitle();
  123.        
  124.            // have to call RefreshViews because this is the buttonPressedScript,
  125.            // the view otherwise wouldn't get refreshed until the user lifted the
  126.            // pen!  If you had done this in the buttonClickScript instead, you
  127.            // could skip the RefreshViews() call.
  128.            RefreshViews();
  129.        end,
  130.      copyright: "Copyright 1993-1994 Apple Computer, Inc.",
  131.      debug: "nextMonthButton",
  132.      _proto: @198
  133.     };
  134. AddStepForm(protoDatePicker, nextMonthButton);
  135.  
  136.  
  137.  
  138. monthView :=
  139.     {viewBounds: {top: 15, left: 1, right: -1, bottom: -1},
  140.      viewFlags: 513,
  141.      viewFormat: nil,
  142.      labelFont: ROM_fontSystem9Bold,
  143.      dateFont: ROM_fontSystem9,
  144.      viewJustify: 246,
  145.      singleDay: true,
  146.      debug: "monthView",
  147.      viewClass: 80
  148.     };
  149. AddStepForm(protoDatePicker, monthView);
  150. StepDeclare(protoDatePicker, monthView, 'monthView);
  151.  
  152.  
  153.  
  154.  
  155. constant |layout_protoDatePicker| := protoDatePicker;
  156. // End of file protoDatePicker
  157. // Beginning of file DatePick.t
  158.  
  159. // Before Script for "monthPickerExample"
  160. //Copyright 1993-1994 Apple Computer, Inc.
  161.  
  162.  
  163. monthPickerExample :=
  164.     {title: "clMonthView Sample",
  165.      viewBounds: {top: 0, left: 0, right: 240, bottom: 335},
  166.      viewFlags: 516,
  167.      selectedDates: [],
  168.      viewSetupFormScript:
  169.        func()
  170.        begin
  171.        local b := GetAppParams();
  172.        constant kMaxWidth := 240;
  173.        constant kMaxHeight := 336;
  174.        
  175.        viewBounds := RelBounds(b.appAreaLeft, b.appAreaTop,
  176.                Min(b.appAreaWidth, kMaxWidth),
  177.                Min(b.appAreaHeight, kMaxHeight) );
  178.        
  179.        
  180.            selectedDates := [Time()];
  181.        
  182.        end,
  183.      debug: "monthPickerExample",
  184.      _proto: @157
  185.     };
  186.  
  187. datePicker :=
  188.     {viewBounds: {left: 41, top: 25, right: 161, bottom: 113},
  189.      viewFormat: 336,
  190.      debug: "datePicker",
  191.      _proto: protoDatePicker
  192.     };
  193. AddStepForm(monthPickerExample, datePicker);
  194. StepDeclare(monthPickerExample, datePicker, 'datePicker);
  195.  
  196.  
  197.  
  198. _view000 :=
  199.     {text: "Today",
  200.      buttonClickScript:
  201.        func()
  202.        begin
  203.            selectedDates := [Time()]; // get current date/time
  204.            datePicker:Refresh();
  205.        end,
  206.      viewBounds: {left: 44, top: 124, right: 160, bottom: 144},
  207.      _proto: @226
  208.     };
  209. AddStepForm(monthPickerExample, _view000);
  210.  
  211.  
  212.  
  213.  
  214. constant |layout_DatePick.t| := monthPickerExample;
  215. // End of file DatePick.t
  216.  
  217.  
  218.  
  219.